package Test;

import static org.junit.Assert.assertTrue;
import java.io.File;
import org.junit.Test;
import Task25.Controller;

public class delTest {

	@Test
	public void delAbsFile() {
		String srcPath = "C:\\Test\\Test1\\1.txt";
		String delPath = "C:\\Test\\Test1\\del1.txt";
		copy(srcPath, delPath);
		command(delPath);
		assertTest(delPath);
	}

	@Test
	public void delRelFile() {
		// change the work directory on the Test
		Controller.gui(new String[] { "cd", "C:\\Test" });
		String srcPath = "Test1\\1.txt";
		String delPath = "Test1\\del1.txt";
		copy(srcPath,delPath);
		command(delPath);
		assertTest("C:\\Test\\" + delPath);
	}

	@Test
	public void delAbsEmptyFolder() {
		String srcPath = "C:\\Test\\Test2";
		String delPath = "C:\\Test\\delTest2";
		copy(srcPath,delPath);
		command(delPath);
		assertTest(delPath);
	}

	@Test
	public void delRelEmptyFolder() {
		// change the work directory on the Test
		Controller.gui(new String[] { "cd", "C:\\Test" });
		String srcPath = "Test2";
		String delPath = "delTest2";
		copy(srcPath,delPath);
		command(delPath);
		assertTest("C:\\Test\\" + delPath);
	}

	@Test
	public void delAbsFolder() {
		String srcPath = "C:\\Test\\Test1";
		String delPath = "C:\\Test\\delTest1";
		copy(srcPath,delPath);
		command(delPath);
		assertTest(delPath);
	}

	@Test
	public void delRelFolder() {
		// change the work directory on the Test
		Controller.gui(new String[] { "cd", "C:\\Test" });
		String srcPath = "Test1";
		String delPath = "delTest1";
		copy(srcPath,delPath);
		command(delPath);
		assertTest("C:\\Test\\" + delPath);
	}

	// the created command and transfered him in the Controller
	private void command(String srcPath) {
		String[] command = { "del", srcPath};
		Controller.gui(command);
	}

	// the verified the work of command
	private void assertTest(String delPath) {
		assertTrue(!new File(delPath).exists());
	}
	
	//the copy deleting file or folder
	private void copy(String srcPath, String delPath){
		String[] command = {"copy", srcPath, delPath};
		Controller.gui(command);
	}
}
